package org.ccams.tran;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.ccams.domain.TSalesordersD;

public class Tran151181 extends AbstractJsonTran {

	@SuppressWarnings("unchecked")
	public void buildJSONObject(Map model, JSONObject json,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		String id = request.getParameter("id");
		int idt_salesorders_h;
		System.out.println(request.getParameter("id"));
		if (id == "" || id.equals("")) {
			idt_salesorders_h = 0;
		} else {
			idt_salesorders_h = Integer.parseInt(id);
		}

		System.out.println("----------------------------------------------");
		System.out.println("成功进入交易代码,id为:" + idt_salesorders_h);
		System.out.println("----------------------------------------------");
		HashMap<String, Object> jsonMap = new HashMap<String, Object>();
		ArrayList<TSalesordersD> al = new ArrayList<TSalesordersD>();
		List<TSalesordersD> list = getCcamsService().getTsalesordersdDao()
				.getTSalesordersD(idt_salesorders_h);

		for (TSalesordersD t : list) {
			TSalesordersD u = new TSalesordersD();
			u.setIdt_salesorders_h(t.getIdt_salesorders_h());
			u.setLine_id(t.getLine_id());
			u.setGoodsid(t.getGoodsid());
			u.setRequest_date(t.getRequest_date());
			u.setSchedule_ship_date(t.getSchedule_ship_date());
			u.setSchedule_arrival_date(t.getSchedule_arrival_date());
			u.setProductdate(t.getProductdate());
			u.setOrder_date(t.getOrder_date());
			u.setGoodsname(t.getGoodsname());
			u.setSpec(t.getSpec());
			u.setSale_price(t.getSale_price());
			u.setOrder_quantity_uom(t.getOrder_quantity_uom());
			u.setFlow_status_code(t.getFlow_status_code());
			u.setAttrib1(t.getAttrib1());
			u.setAttrib1_unit(t.getAttrib1_unit());
			u.setAttrib2(t.getAttrib2());
			u.setAttrib2_unit(t.getAttrib2_unit());
			u.setAttrib3(t.getAttrib3());
			u.setAttrib3_unit(t.getAttrib3_unit());
			u.setAttrib4(t.getAttrib4());
			u.setAttrib4_unit(t.getAttrib4_unit());
			u.setAttrib5(t.getAttrib5());
			u.setAttrib5_unit(t.getAttrib5_unit());

			al.add(u);
		}
		JSONArray JsonArray = JSONArray.fromObject(al); // 得到JSON数组
		jsonMap.put("root", JsonArray);
		json.putAll(jsonMap);

	}
}
